using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_SanPham_ChiTietBinhLuan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }

    }

    #region"Load Data"
    private void LoadData()
    {
        int id = int.Parse(Request.QueryString["id"]);
        tbBinhLuan binhLuan = tbBinhLuanBUS.GetByID(id);
        lit_MaBL.Text = binhLuan.MaBL.ToString();

        tbKhachHang khachHang = tbKhachHangBUS.GetByID(binhLuan.MaKH);
        lit_TenKH.Text = khachHang.HoTen;

        tbSanPham sanPham = tbSanPhamBUS.GetByID(binhLuan.MaSP);
        lit_TenSP.Text = sanPham.TenSP;
        lit_NgayGui.Text = binhLuan.NgayGui.ToShortDateString();
        lit_NoiDung.Text = binhLuan.NoiDung;

        pager.PageSize = 5;
        Criteria c = new Criteria();
        c.add(Condition.AND, tbTraLoiColumns.MaBL, Condition.EQUAL, id);
        int total = 0;
        tbTraLoiCollection traLoiCollection =
            tbTraLoiBUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
            tbTraLoiColumns.MaTL.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = traLoiCollection;
        Repeater1.DataBind();
        pager.ItemCount = total;



    }
    #endregion
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
              e.Item.ItemType == ListItemType.Item)
        {
            tbTraLoi traLoi = (tbTraLoi)e.Item.DataItem;

            tbKhachHang khachHang = tbKhachHangBUS.GetByID(traLoi.MaKH);
            Literal lit_TenKH = (Literal)e.Item.FindControl("lit_TenKH");
            lit_TenKH.Text = khachHang.HoTen;

            Literal lit_NgayGui = (Literal)e.Item.FindControl("lit_NgayGui");
            lit_NgayGui.Text = traLoi.NgayTraLoi.ToShortDateString();

        }

    }
    protected void lbt_Xoa_Click1(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cb_Xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
               tbTraLoiBUS.Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);

    }
}
